﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SQLite;
using Com.Toook.AutoDownloadHtml.Util;

public partial class jokelist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            InitJokeList(0);
            InitJokeList(1);
            InitJokeList(2);
            InitJokeList(3);
            InitJokeList(4);
            InitJokeList(5);
        }
    }
    private void InitJokeList(int n)
    {
        int start = n * 10;
        
        string sql = "select id, title from UncheckedJokeHaha365 limit " + 
            start.ToString() + ", 10 ";
        SQLiteConnection conn = SqliteHelper.GetConnection("SQLiteDatabase");
        SQLiteCommand cmd = new SQLiteCommand(sql, conn);
        SQLiteDataReader reader = null;
        try
        {
            conn.Open();
            reader = cmd.ExecuteReader();
            if(n == 0)
            {
                rptLeft.DataSource = reader;
                rptLeft.DataBind();
            }
            else if(n == 1)
            {
                rptMiddle.DataSource = reader;
                rptMiddle.DataBind();
            }
            else if(n == 2)
            {
                rptRight.DataSource = reader;
                rptRight.DataBind();
            }
            else if(n == 3)
            {
                rptLeft1.DataSource = reader;
                rptLeft1.DataBind();
            }
            else if(n == 4)
            {
                rptMiddle1.DataSource = reader;
                rptMiddle1.DataBind();
            }
            else if(n == 5)
            {
                rptRight1.DataSource = reader;
                rptRight1.DataBind();
            }
        }
        finally
        {
            SqliteHelper.CloseDbResource(conn, reader);
        }
    }
}
